package com.huike.web.controller.report;

import java.util.*;

import com.huike.common.core.domain.entity.SysDictData;
import com.huike.common.utils.DictUtils;
import com.huike.report.domain.vo.LineChartVO;
import com.huike.report.domain.vo.LineSeriesVO;
import com.huike.report.domain.vo.contractVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.TbClue;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.service.IReportService;


@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

    @Autowired
    private IReportService reportService;

    /**
     * 客户统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO contractStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return reportService.contractStatistics(beginCreateTime, endCreateTime);
    }

    /**
     * 销售统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO salesStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return reportService.salesStatistics(beginCreateTime, endCreateTime);
    }


    /**
     * 渠道统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult chanelStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return AjaxResult.success(reportService.chanelStatistics(beginCreateTime, endCreateTime));
    }


    /**
     * 活动统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult activityStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return AjaxResult.success(reportService.activityStatistics(beginCreateTime, endCreateTime));
    }

    /**
     * 查询活动管理列表
     */
    @GetMapping("/contractStatisticsList")
    public TableDataInfo contractStatisticsList(TbContract contract) {
        startPage();
        List<TbContract> list = reportService.contractReportList(contract);
        return getDataTable(list);
    }


    /**
     * 销售统计部门报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo deptStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        startPage();
        List<Map<String, Object>> list = reportService.deptStatisticsList(beginCreateTime, endCreateTime);
        return getDataTablePage(list);
    }

    /**
     * 销售统计渠道报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/channelStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo channelStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        startPage();
        List<Map<String, Object>> list = reportService.channelStatisticsList(beginCreateTime, endCreateTime);
        return getDataTablePage(list);
    }

    /**
     * 销售统计归属人报表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo ownerShipStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        startPage();
        List<Map<String, Object>> list = reportService.ownerShipStatisticsList(beginCreateTime, endCreateTime);
        return getDataTablePage(list);
    }


    /**
     * 线索统计报表
     *
     * @param clue
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    public TableDataInfo cluesStatisticsList(TbClue clue) {
        startPage();
        List<TbClue> list = reportService.cluesStatisticsList(clue);
        return getDataTable(list);
    }

    /**
     * 活动渠道统计
     *
     * @param activity
     * @return
     */
    @GetMapping("/activityStatisticsList")
    public TableDataInfo activityStatisticsList(TbActivity activity) {
        List<ActivityStatisticsVo> list = reportService.activityStatisticsList(activity);
        return getDataTablePage(list);
    }

    //查询在一段时间当中发生的数据
//    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
//    public AjaxResult sub(@PathVariable("beginCreateTime")String beginCreateTime,@PathVariable("endCreateTime")String endCreateTime){
////                   查询对应时间段当中的数据
//        List<HashMap<String, Object>> member = reportService.findMember(beginCreateTime, endCreateTime);
//        for (HashMap<String, Object> map : member) {
//            String subject = (String)map.get("subject");
//            String label = DictUtils.getDictLabel("course_subject", subject);
//            Object o = map.get("subject");
//            map.put("subject",label);
//        }
//        return AjaxResult.success(member);
//
//    }
//
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult sub(@PathVariable("beginCreateTime") String beginCreateTime, @PathVariable("endCreateTime") String endCreateTime) {
//        contractVo contractVo = new contractVo();
//        contractVo.setSubject("java");
//        contractVo.setNum(60);
//        contractVo.setSubject("java1");
//        contractVo.setNum(600);
//        ArrayList<contractVo> list = new ArrayList<>();
//        list.add(contractVo);
        List<contractVo> member = reportService.findMember(beginCreateTime, endCreateTime);
        return AjaxResult.success(member);
    }

//    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO doLine11(@PathVariable("beginCreateTime") String beginCreateTime, @PathVariable("endCreateTime") String endCreateTime){
//        返回一个linechartvo对象
        LineChartVO vo = new LineChartVO();
//        第一个数据
        List<String> list = vo.getxAxis();
        list.add("2022-04-18");
        list.add("2022-04-19");
        list.add("2022-04-20");
        list.add("2022-04-21");
        list.add("2022-04-22");
//        第二个数据  大集合装小集合
        List<LineSeriesVO> series = vo.getSeries();
        LineSeriesVO seriesVO=new LineSeriesVO();
        ArrayList<Object> list1 = new ArrayList<>();
        list1.add(0);
        list1.add(499);
        list1.add(104);
        list1.add(0);
        list1.add(0);
        seriesVO.setName("新增线索总量");
        seriesVO.setData(list1);
        series.add(seriesVO);
//        存储的但是这样的类型
        vo.setSeries(series);
        return vo;
    }
}
